$(document).ready(function() {
	

	// 滑动加载中奖纪录列表
	var stop = true;
	var page = 1;
	function show(){
		$.ajax({
			url: lucky_draw_record,
			type: 'get',
			data: {
				page: page
			},
			success: function(data) {
				var html = '';
				var data = JSON.parse(data)
				if (data.code == 1) {
					for (var i = 0; i < data.data.record_lst.length; i++) {
						html += '<li>'+
									'<div class="lucky_draw_recordimg"><img src="'+data.data.record_lst[i].product_thumb_img+'" alt=""></div>'+
									'<div class="lucky_draw_recordtit">'+
										'<h1>'+data.data.record_lst[i].product_title+'</h1>'+
										'<p>'+new Date(data.data.record_lst[i].create_time * 1000).toLocaleString().replace(/\-(\d)\b/g, "-0$1")+'</p>'+
									'</div>';
									if (data.data.record_lst[i].product_type == 2 || data.data.record_lst[i].product_type == 3 || data.data.record_lst[i].order_id != 0) {
										html+='<div class="zhuangtai yiling">'+get_status+'</div>'
									}else{
										html+=' <div id="lijilingqu_'+data.data.record_lst[i].lucky_record_id+'" data-src="'+data.data.record_lst[i].product_thumb_img+'"  class="zhuangtai lijilingqu" data-product="'+data.data.record_lst[i].product_id+'" data-title="'+data.data.record_lst[i].product_title+'"  data-lucky_record_id="'+data.data.record_lst[i].lucky_record_id+'" >'+slots_receive_the_prize+'</div>'
									}
									
	    				html+='</li>'
					};
				}else{
					$(".Loading").html(load_faild);
				}
			
				
				$('.lucky_draw_record ul').append(html)
				stop = true;
				page++;
				if (data.data.record_lst.length < 10) {
					$(".Loading").html(npoint_record_all);
					stop = false;
				}else{
					$(".Loading").html("loading···");
				}

				if(data.data.record_lst.length == 0) {
					$(".Loading").html(slots_record_empty);
				}
			},
			error:function(xhr, textStatus){
				if(xhr.status == 401){
					 window.location.href = "/Npoint_store/Login";
				} else if(xhr.status == 0){
					alert(interneterror)
				}else{
					alert(errordata)
				}

			}
		})
	}
	show()
	// loading  加载
	$(window).scroll(function() {
		var totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
		if ($(document).height() <= totalheight) {
			if (stop == true) {
				stop = false;
				show()
			}
		}
	});














	// var lucky_record_id = decodeURIComponent((new RegExp('[?|&]lucky_record_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// var address_id = decodeURIComponent((new RegExp('[?|&]address_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// var product_id = decodeURIComponent((new RegExp('[?|&]product_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// var shows = decodeURIComponent((new RegExp('[?|&]shows=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// 如果show = 1 显示弹窗
	// if (shows == 1) {
	//  	$.ajax({
	//  		url: lucky_solits_record_attr,
	//  		type: 'POST',
	//  		data: {
	//  			product_id: product_id,
	//  			address_id: address_id
	//  		},
	//  		success: function(data) {
	//  			var data = JSON.parse(data)
	//  			console.log(data)
	//  			$('.detail_select_xh ul').html('')
	//  			for (var i = 0; i < data.data.attr.length; i++) {
	//  				$('.detail_select_xh ul').append('<li data-c="' + data.data.attr[i].attr_id + '">' + data.data.attr[i].attr_name + '</li>')
	//  			}
	//  			var html = ''
	//  			if(data.data.address != ""){
	//  				html += '<div class="name_tel">' +
	//  				'<span class="name">' + data.data.address.name + '</span>' +
	//  				'<span class="tel">' + data.data.address.tel + '</span>' +
	//  				'</div>' +
	//  				'<div class="ads" data-lucky_record_id="' + lucky_record_id + '" data-productid = "' + data.data.attr[0].product_id + '">' +
	//  				'<span class="address" data-address="' + data.data.address.address_id + '">' + data.data.address.province + data.data.address.city + data.data.address.address + '</span>' +
	//  				'</div><img src="'+public_url+'/images/info.png" class="right_info" alt="">'
	//  			}else{
	//  				html += '<div class="name_tel">请填写收货地址</div>'
	//  			}
	//  			$('.order_address').html(html)
	 			
	//  			if (url_e !== null && url_e.attr_id != '') { 
	//  				console.log(url_e.attr_id);
	//  				$('.detail_select_xh li[data-c=' + url_e.attr_id + ']').addClass('cur');
	//  				xinghao = url_e.attr_id;
	//  			}else{
	 				 
	//  			}
	//  		},
	//  		error:function(xhr, textStatus){
	//  			if(xhr.status == 401){
	//  				 window.location.href = "/Npoint_store/Login";
	//  			}else{
	//  				alert('系统错误')
	//  			}

	//  		}
	//  	})
	//  	$('.detail_select').show();
	//  	$('.detail_mask').show();
	//  }




	




	// var xinghao = ''
	// var lingqu = function(thisq, url_e = null) {
	var lingqu = function(thisq, url_e) {
		var lucky_record_id = thisq.attr('data-lucky_record_id');
		$('.detail_select_money span').html(thisq.attr('data-title'))
		$('.detail_select_logo').attr("data-luckyrecord_id",lucky_record_id)
		var productid = thisq.attr('data-product');
		$('.detail_select_logo img').attr("src",thisq.attr('data-src')) //显示logo图片
		// if (url_e == null) {
		// 	var productid = thisq.attr('data-product');
		// }
		// else{
		// 	alert(url_e)
		// 	var productid = url_e.product_id;
		// }
		// var address_id = getCookie('select_address');
		$('.detail_select').show();
		$('.detail_mask').show();
		$.ajax({
			url: lucky_solits_record_attr,
			type: 'POST',
			data: {
				product_id: productid
				// address_id: address_id
			},
			success: function(data) {
				var data = JSON.parse(data)
				console.log(data)
				$('.detail_select_xh ul').html('')
				for (var i = 0; i < data.data.attr.length; i++) {
					$('.detail_select_xh ul').append('<li data-productid = ' + data.data.attr[0].product_id + '  data-c="' + data.data.attr[i].attr_id + '">' + data.data.attr[i].attr_name + '</li>')
				}
				var html = ''
				// if(data.data.address != ""){
				// 	html += '<div class="name_tel">' +
				// 	'<span class="name">' + data.data.address.name + '</span>' +
				// 	'<span class="tel">' + data.data.address.tel + '</span>' +
				// 	'</div>' +
				// 	'<div class="ads" data-lucky_record_id="' + lucky_record_id + '" data-productid = "' + data.data.attr[0].product_id + '">' +
				// 	'<span class="address" data-address="' + data.data.address.address_id + '">' + data.data.address.province + data.data.address.city + data.data.address.address + '</span>' +
				// 	'</div><img src="'+public_url+'/images/info.png" class="right_info" alt="">'
				// }else{
				// 	html += '<div class="name_tel">请填写收货地址</div>'
				// }
				// $('.order_address').html(html)
				// if (url_e !== null && url_e.attr_id != '') { 
				// 	console.log(url_e.attr_id);
				// 	$('.detail_select_xh li[data-c=' + url_e.attr_id + ']').addClass('cur');
				// 	xinghao = url_e.attr_id;
				// }else{
					 
				// }
			},
			error:function(xhr, textStatus){
				if(xhr.status == 401){
					 window.location.href = "/Npoint_store/Login";
				}else{
					alert('系统错误')
				}

			}
		})
	}




	























	// 立即领取实物
	$(document).on('click', '.lijilingqu', function() {
		lingqu($(this))
		
	})


	// 选择属性
	$(document).on('click', '.detail_select_xh li', function() {
		$(this).addClass('cur').siblings().removeClass('cur');
		$('.detail_select_sx').html('已选择:<span class="detail_select_xinghao">'+$(this).html()+'</span>')
		// xinghao = $(this).attr('data-c')
	})
	
	

	// 更换地址
	// $(document).on('click', '.order_content', function() {
	// 	var productid = $(this).find('.ads').attr('data-productid')
	// 	var lucky_record_id = $(this).find('.ads').attr('data-lucky_record_id')
	// 	var arr = {};
	// 	arr.attr_id = xinghao;
	// 	arr.product_id = productid;
	// 	arr.action = 'lucky_solts_record';
	// 	arr.lucky_record_id = lucky_record_id;
	// 	var url_extend = JSON.stringify(arr);
	// 	SetCookie('product_order', url_extend)
		
	// 	window.location.href = addressurl + '?action=lucky_solts_record&lucky_record_id='+lucky_record_id;
	// })


	// $('.order_content').click(function(event) {
	// 	var productid = $(this).find('.ads').attr('data-productid')
	// 	var lucky_record_id = $(this).find('.ads').attr('data-lucky_record_id')
	// 	var arr = {};
	// 	arr.attr_id = xinghao;
	// 	arr.product_id = productid;
	// 	arr.action = 'lucky_draw_record_list';
	// 	arr.lucky_record_id = lucky_record_id;
	// 	var url_extend = JSON.stringify(arr);
	// 	SetCookie('url_extend', url_extend)
		
	// 	window.location.href = addressurl + '?action=lucky_draw_record_list';
	// });


	// 默认显示状态
	// var url_e = getCookie('url_extend')
	// if (url_e) {
	// 	var url_e = JSON.parse(getCookie('url_extend'));
	// 	if (url_e.action == 'lucky_draw_record_list') {
	// 		lingqu($('#lijilingqu_' + url_e.lucky_record_id), url_e);
	// 		SetCookie('url_extend', '');
	// 	}
	// }

	// $('.close ,.jiang_again').click(function(event) {
	// 	$('.mask ,.close ,.jiangimg').css('display', 'none')
	// });
	// 关闭
	$('.detail_select_close').click(function(event) {
		$('.detail_select').hide();
		$('.detail_mask').hide();
	});



// 点击领取按钮  通过url传递参数
	$('.lingjiang').click(function(event) {
		// var address_id = $(this).parent().find('.address').attr('data-address')
		// var product_id = $(this).parent().find('.ads').attr('data-productid')
		var product_id = $(this).parent().find('.cur').attr('data-productid')
		var lucky_record_id = $(this).parent().find('.detail_select_logo').attr("data-luckyrecord_id")//中奖纪录id
		// var attr_id = getCookie('url_extend')
		var datac = $('.cur').attr('data-c')  //属性id
		$('.detail_select_xh li').each(function(index, el) {
			if ($('.detail_select_xh li').hasClass('cur')) {
 				window.location.href = localhosthref+ 'confirm_order_detail?product_id='+product_id+'&datac='+datac+"&sorce=4&lucky_record_id="+lucky_record_id
			}else{
				alert('请选择属性')
				return false
			}
		});




	
		// 在当前页面领取
		// $.ajax({
		// 	url: lingquurl,
		// 	type: 'POST',
		// 	data: {
		// 		address_id: address_id,
		// 		product_id: product_id,
		// 		attr_id: xinghao,
		// 		sorce: 4,
		// 		lucky_record_id: lucky_record_id,
		// 	},
		// 	success: function(data) {
		// 		var data = JSON.parse(data)
		// 		if (data.code == 2) {
		// 			alert(data.desc)
		// 		} else {
		// 			window.location.reload();
		// 		}
		// 	},
		// 	error: function(xhr, textStatus) {
		// 		if (xhr.status == 401) {
		// 			window.location.href = "/Npoint_store/Login";
		// 		} else {
		// 			alert(xhr.status);
		// 			alert('系统错误')
		// 		}
		// 	}
		// })
		
		
	});







});




